﻿using DL.Animation;
using Messegers;
using UnityEngine;

namespace DL.Health
{
    public class PlayerHealthController : CharacterHealthBase
    {
        
        public PlayerHealthController(Characters.Actor actor) : base(actor)
        {
        }
        
        protected override void Damaged(float damaged)
        {
            if(CharacterHealth == null) return;
            //扣除生命值
            CharacterHealth.ChangeForHp(-damaged);
            
            if (CharacterHealth.IsDead)
            {
                Animator.SetBool(AnimatorParameter.Dealth,true);
                Animator.Play(AnimatorTag.Dead);
                SetCharacterLayer(GodLayer);
                Messenger<Transform>.Broadcast(MessengerName.MSG_DealthEvt, Self);
            }
        }
        
        protected override void CharacterHit(string hitName, string parryName, float damaged)
        {
            if (CharacterHealth == null) return;//记得面板把母版拖进去,没错，说的就是你。不然打人没反应,这里的条件是防止你忘记拖母版，导致空引用报错
            
            Animator.Play(hitName,0,0f);
            Damaged(damaged);
         
            //音效
            // AudioManager.Inst.CreateAudio().WithSoundType(SoundType.KatanaHit).WithPosition(Self.position).Play();
        }

        
    }
}